Repository navigation
Remove legacy decorators - #927
Conversation
|
Thanks @dmamelin. This is for the release after the next one, right? |
hassfest accepted the mqtt import only because of the legacy mqtt.py file, which it treated as an mqtt platform of pyscript.
…ional-only Follow-up to custom-components#926: keyword arguments such as func, task, callback, domain, name or event_type are now passed on to the called function, the service data or the event data, instead of clashing with the parameters of task.create, task.executor, task.add_done_callback, service.call and event.fire.
f37926d to
74c17d2
Compare
|
Added the follow-up from #926: the internal parameters of |
|
@craigbarratt about the release: when I suggested releasing 2.2.0 right after #899, I didn't expect so much to land in between. There are now 52 commits on master since 2.1.1 (#870 through #926), so a release with only the new |
|
Yes, we are in the world of AI PRs and issues, and I'm using AI to try to keep up. I agree with your approach. It's a major release already. Please tell me when you think this PR is ready for review. |
|
This PR is ready for review; there were only some technical issues. Since I opened it, I rebased it on #926 and added two commits: I don't think we should release before #925 is fixed, though. The bug is rare, but completely silent: the script keeps running with the wrong values and nothing is logged. Over the next few days I'll try to look into the AI-written code during my coffee breaks. |
craigbarratt
left a comment
There was a problem hiding this comment.
Thanks @dmamelin, this is a big cleanup, and splitting the moves from the changes made it easy to review. I compared every definition that moved out of trigger.py with the original. Apart from the dropped legacy wait_until, the init changes and dt_now, they're identical, and the task.* functions moved unchanged. The config entry migration and cv.removed look right.
I also checked task.create, task.add_done_callback, task.executor, service.call and event.fire with colliding keywords, and the #905 warning through a **kwargs wrapper (logged once per function), and they all behave as described.
One thing for a follow-up: several comments still say to change something once the legacy subsystem is removed (decorator_abc.py 88 and 268, decorators/service.py 113–117, plus the "Keep this wording for transition compatibility" in decorators/state.py 101 and decorators/timing.py 450). Now's the time to update those messages and tests, or drop the comments. That includes the @service reserved-name check, which still doesn't look at the domain.
|
Thanks @craigbarratt for the review! I left those messages and comments on purpose, to keep this PR from growing. I have another PR in progress that points decorator errors at their exact location in the script, and it already includes updating these legacy messages. It was almost ready; I'll start adapting it to #921 soon, which will probably need significant changes. The messages don't affect behaviour, so if there are no other comments, this can be merged now. |
|
Thanks @dmamelin; merging now. |
Removes the legacy decorator subsystem (
legacy_decorators: true).Changes
legacy_decoratorsoption removed. If it's still inconfiguration.yaml, it's dropped with an error in the log (cv.removed) and the config stays valid. Config entries are migrated to 1.2, which drops the key fromentry.data(for entries set up from the UI).trigger.py,event.py,mqtt.pyandwebhook.pyremoved. What is still used moved almost unchanged:TrigTime(time specs for@time_trigger/@time_active) →decorators/timing.pyident_*,strip_trigger_expr,any_trigger_exprs→decorators/state.pydt_now→decorator_abc.pytask.create,task.add_done_callback,task.executor→ newtask_functions.py(see below)trigger_init, only the logger /global_ctx_nameswitch is kept, so a function wrapped by a decorator from a module still logs under the script that defines it.TRIGGER_KWARGSnow log a warning, once per function definition (Unexpected keyword arguments are silently ignored when their names are in TRIGGER_KWARGS #905). A common case is a wrapper that passes all its**kwargson to a function that doesn't declare them; in Python that's aTypeError.mqtttoafter_dependenciesin the manifest. hassfest accepted the mqtt import only because of the oldmqtt.py, which it treated as an mqtt platform of pyscript.task.create,task.executor,task.add_done_callback,service.callandevent.fireare now positional-only, so keywords likefunc,domain,nameorevent_typego to the called function, the service data or the event data.The commits are split for review; the moves are separate from the changes. The moved code is kept almost as it was, so it's easy to compare with the old
trigger.py:TrigTime.initis now called from the time decorators'validate(), and thetask.*closures becameTaskFunctionsmethods. The code could use some cleanup and reorganization (for example,TrigTimeitself), but that's out of scope for this PR.task_functions.pytask.create,task.add_done_callbackandtask.executorwere registered inTrigTime.init, which wasn't a good place for them:TrigTimehandles time specs. They were there only because they needAstEval/EvalFunc/EvalFuncVar, andfunction.pycan't importeval.py(eval.pyimportsfunction.py). I kept your pattern:Functiondoesn't depend oneval, and modules that needevalregister their own functions, likeState.register_functions(). So they are now in aTaskFunctionsclass withregister_functions().The other
task.*functions (sleep,cancel,current_task,wait,remove_done_callback,unique,name2id) are still inFunction. Would you like alltask.*functions in one place? If so, I'd do that in a separate PR.task.uniqueandtask.name2iduseFunctioninternals (unique_name_used, andTaskUniqueDecoratorcallstask_unique_factory), so they may be better left where they are.